package me.mock.ingress;

import android.location.Location;
import android.location.LocationManager;
import android.os.SystemClock;

public class NamedLocation
{
	private String name;
	private long lat;
	private long lon;

	public NamedLocation(NamedLocation other)	
	{
		name = other.name;
		lat = other.lat;
		lon = other.lon;
	}

	public NamedLocation(String name, double lat, double lon)
	{
		this.name = name;
		this.lat = (long) (lat * 1000000);
		this.lon = (long) (lon * 1000000);
	}

	public void update(long latDelta, long lonDelta)
	{
		lat += latDelta;
		lon += lonDelta;
	}
	
	public double getDoubleLatitude()
	{
		return ((double) lat) / 1000000.0f;
	}
	
	public double getDoubleLongitude()
	{
		return ((double) lon) / 1000000.0f;
	}

	public Location toLocation()
	{
		Location loc = new Location(LocationManager.GPS_PROVIDER);
		loc.setAccuracy(10.0f);
		loc.setLatitude(getDoubleLatitude());
		loc.setLongitude(getDoubleLongitude());
		loc.setTime(System.currentTimeMillis());
		loc.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
		return loc;
	}

	@Override
	public boolean equals(Object o)
	{
		if (o == null)
			return false;

		if (!(o instanceof NamedLocation))
			return false;

		NamedLocation other = (NamedLocation) o;
		return lat == other.lat && lon == other.lon;
	}
	
	public long distanceTo(NamedLocation other)
	{
		Location loc1 = this.toLocation();
		Location loc2 = other.toLocation();
		return (long) loc1.distanceTo(loc2);
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public long getLat()
	{
		return lat;
	}

	public void setLat(long lat)
	{
		this.lat = lat;
	}

	public long getLon()
	{
		return lon;
	}

	public void setLon(long lon)
	{
		this.lon = lon;
	}
	
	
}
